﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace dFactor2.Dialogs
{
    public partial class ConstructorBuilder : Form
    {
        private Dictionary<string, string> _availableProperties;

        private Dictionary<string, string> _selectedProperties;

        public Dictionary<string, string> SelectedProperties
        {
            get { return _selectedProperties; }
            set { _selectedProperties = value; }
        }

        public ConstructorBuilder(Dictionary<string, string> availableProperties)
        {
            _availableProperties = availableProperties;
            _selectedProperties = new Dictionary<string, string>();

            InitializeComponent();
            InitializePropertyList();
        }

        private void InitializePropertyList()
        {
            lstProperties.BeginUpdate();
            lstProperties.Items.Clear();

            foreach (string k in _availableProperties.Keys)
            {
                ListViewItem lvi = new ListViewItem();
                lvi.SubItems.Add(k);
                lvi.SubItems.Add(_availableProperties[k]);

                lstProperties.Items.Add(lvi);
            }

            lstProperties.EndUpdate();

            lstProperties.Columns[0].AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize);
            lstProperties.Columns[1].AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent);
            lstProperties.Columns[2].AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize);
        }

        private void btnCreate_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem lvi in lstProperties.Items)
            {
                if (lvi.Checked)
                {
                    _selectedProperties.Add(lvi.SubItems[1].Text, lvi.SubItems[2].Text);
                }
            }

            DialogResult = System.Windows.Forms.DialogResult.OK;
            
        }
    }
}
